package com.usian.admin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.admin.mapper.AdChannelMapper;
import com.usian.model.admin.pojos.AdChannel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
@SuppressWarnings("ALL")
public class AdChannelDemo {

    @Autowired
    private AdChannelMapper adChannelMapper;

    //@Test
    public void findAll(){
        List<AdChannel> list =  adChannelMapper.selectList(null);
        list.stream().forEach(x->{
            System.out.println(x.getName());
        });
    }

    // 条件查询
    //@Test
    public void findBySearch(){
        String name = "v";
        LambdaQueryWrapper<AdChannel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        if(name!=null && !"".equals(name)){
//            lambdaQueryWrapper.like(AdChannel::getName,name);
//        }

        lambdaQueryWrapper.like(name!=null && !"".equals(name), AdChannel::getName,name);

        List<AdChannel> list = adChannelMapper.selectList(lambdaQueryWrapper);

    }


   // @Test
    public void findBySearchPage(){
        String name = "v";
        LambdaQueryWrapper<AdChannel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        if(name!=null && !"".equals(name)){
//            lambdaQueryWrapper.like(AdChannel::getName,name);
//        }

        lambdaQueryWrapper.like(name!=null && !"".equals(name), AdChannel::getName,name);

        Page<AdChannel> page = new Page<>(1,3);
        IPage<AdChannel> iPage = adChannelMapper.selectPage(page,lambdaQueryWrapper);
        System.out.println(iPage.getTotal());
        System.out.println(iPage.getRecords());

    }



}
